if (!defined("IN_FUSION")) { header("Location:../../index.php"); exit; }

if (file_exists(INFUSIONS."latestcomments_panel/locale/".$settings['locale'].".php"))
{
    include INFUSIONS."latestcomments_panel/locale/".$settings['locale'].".php";
}
else
{
    include INFUSIONS."latestcomments_panel/locale/English.php";
}

define("SAFEMODE", @ini_get("safe_mode") ? true : false);

opentable($locale['LCS_100']);

$show_pThumb = true;
$showontop = true;
$alignwhere = "left";

function checkImageExists($image_file)
{
    if(file_exists($image_file)) {
    return $image_file;
    }
    else
    {
    return IMAGES."imagenotfound.jpg";
    }
}

$i = 0;
$result = dbquery("SELECT * FROM ".DB_PREFIX."comments LEFT JOIN ".DB_PREFIX."users
                   ON ".DB_PREFIX."comments.comment_name=".DB_PREFIX."users.user_id
                   ORDER BY comment_datestamp DESC LIMIT 3");

if (dbrows($result))
{
    echo "<table width='100%' align='center' cellpadding='0' cellspacing='1' class='tbl-border'>\n";
    while ($data = dbarray($result))
    {
        echo "<tr>\n<td class='".($i% 2==0?"tbl1":"tbl2")."'><div><span class='comment-name'>";
        echo "<span class='small'>";

        if ($data['comment_type'] == "P" && $show_pThumb && $showontop && ($alignwhere == "left" || $alignwhere == "right"))
        {
            echo "<A HREF='".BASEDIR."photogallery.php?photo_id=".$data['comment_item_id']."' class='side'>";
            $data2=dbarray(dbquery("SELECT * FROM ".$db_prefix."photos WHERE photo_id='$data[comment_item_id]'"));
            echo "<IMG SRC='".checkImageExists(PHOTOS.(!SAFEMODE ? "album_".$data2['album_id']."/" : "").$data2['photo_thumb1'])."' width='75' height='70' style='border: 1px solid #FFFFFF' ALIGN='".$alignwhere."'>";
            echo "</A>";
        }

        if ($data['user_avatar'] != "")
        {
            echo "\n";
        }
        else
        {
            echo "\n";
        }

        if ($data['user_name'])
        {
            echo "";
        }
        else
        {
            echo $data['comment_name'];
        }

        $comment_message = nl2br(parseubb($data['comment_message']));
        $comment_item_id = $data['comment_item_id'];
        $comment_type = $data['comment_type'];

        if ($data['comment_smileys'] == "1")
        {
            $comment_message = parsesmileys($comment_message);
        }

        echo "</span>
              <span class='small'>".showdate("forumdate", $data['comment_datestamp'])."</span><br>
             " . trimlink($comment_message,220);
  	

        if (checkrights("C"))
        {
            echo "<div align='left'><a href='".ADMIN."comments.php".$aidlink."&ctype=".$data['comment_type']."&cid=".$data['comment_item_id']."'>".$locale['LCS_101']."</a></div>";
        }

        echo "<b>";

        if ($data['comment_type'] == "P" && $show_pThumb && $showontop && $alignwhere == "none")
        {
            echo "<A HREF='".BASEDIR."photogallery.php?photo_id=".$data['comment_item_id']."' class='gallery'>";
            $data2=dbarray(dbquery("SELECT * FROM ".$db_prefix."photos WHERE photo_id='$data[comment_item_id]'"));
            echo "<IMG SRC='".checkImageExists(PHOTOS.(!SAFEMODE ? "album_".$data2['album_id']."/" : "").$data2['photo_thumb1'])."' title='".$data2['photo_title']."'>";
            echo "</A>";
        }

        if ($data['comment_type'] == "N")
        {
            echo "<a href='".BASEDIR."news.php?readmore=".$data['comment_item_id']."'>".$locale['LCS_102']."</a><br>";
        }
        else if ($data['comment_type'] == "A")
        {
            echo "<a href='".BASEDIR."readarticle.php?article_id=".$data['comment_item_id']."'>".$locale['LCS_103']."</a><br>";
        }
        else if ($data['comment_type'] == "P")
        {
            echo "";
            if ($show_pThumb && !$showontop)
            {
                echo "<br>"; } else { echo "</a></span><br>";
            }
        }
        else if ($data['comment_type'] == "G")
        {
            echo "<a href='".BASEDIR.INFUSIONS."arcade/comments.php?game_id=".$data['comment_item_id']."'>".$locale['LCS_105']."</a><br>";
        }
        else if ($data['comment_type'] == "S")
        {
            echo "<a href='".BASEDIR.INFUSIONS."suggestion_box/suggestion_box.php?step=view&suggestion_id=".$data['comment_item_id']."'>".$locale['LCS_106']."</a><br>";
        }
        else if ($data['comment_type'] == "E")
        {
            echo "<a href='".BASEDIR.INFUSIONS."error_reports/error_reports.php?step=view&error_id=".$data['comment_item_id']."'>".$locale['LCS_107']."</a><br>";
        }
        else if ($data['comment_type'] == "V")
        {
            echo "<a href='".BASEDIR.INFUSIONS."videogallery/videogallery.php?video=".$data['comment_item_id']."'>".$locale['LCS_108']."</a><br>";
        }
        else if ($data['comment_type'] == "U")
        {
            echo "<a href='".BASEDIR."profile.php?lookup=".$data['comment_item_id']."'>".$locale['LCS_109']."</a><br>";
        }
        else if ($data['comment_type'] == "C")
        {
            echo "<a href='".BASEDIR."viewpage.php?page_id=".$data['comment_item_id']."'>".$locale['LCS_110']."</a><br>";
        }
        else
        {
            echo $locale['LCS_111'];
        }

        if ($data['comment_type'] == "P" && $show_pThumb && !$showontop)
        {
            echo "<A HREF='".BASEDIR."photogallery.php?photo_id=".$data['comment_item_id']."' class='gallery'>";
            $data2=dbarray(dbquery("SELECT * FROM ".$db_prefix."photos WHERE photo_id='$data[comment_item_id]'"));
            echo "<IMG SRC='".checkImageExists(PHOTOS.(!SAFEMODE ? "album_".$data2['album_id']."/" : "").$data2['photo_thumb1'])."' title='".$data2['photo_title']."'>";
            echo "</A>";
        }
       
        echo "</td></tr><tr><td><hr /></td></tr>";

        $i++;
    }
    echo "</b>";
    echo "</table>\n";
}
else
{
    echo "<center><br>".$locale['LCS_112']."<br><br></center>\n";
    echo "</td>\n</tr></table>\n";
}
closetable();
